<template>
  <div class="container">
    <div class="box">
      <el-form>
        <el-form-item label="通知标题">
          <el-input v-model="title" placeholder="请输入通知标题"></el-input>
        </el-form-item>
        <el-form-item label="通知内容">
          <el-input type="textarea" v-model="content" placeholder="请输入通知内容"></el-input>
        </el-form-item>
        <el-button @click="Send" type="primary" class="full-width">发布</el-button>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import axios from "axios";
import { ElMessage } from "element-plus";
import { useRoute } from "vue-router";
import { ref } from "vue";

const route = useRoute();
const id = route.query.cno;
let title = ref('');
let content = ref('');

const Send = () => {
  const now = new Date();
  const informVo = {
    title: title.value,
    content: content.value,
    cno: id,
    time_start: now.toISOString(),
    time_end: now.toISOString()
  };
  console.log(informVo);
  axios.post('http://localhost:8080/inform', informVo).catch(error => {
    window.alert('有问题' + error);
  });
  ElMessage({
    type: 'success',
    message: "发布成功",
  });
};
</script>

<style scoped>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f5f7fa;
}

.box {
  width: 400px;
  padding: 24px;
  background-color: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  border: 1px solid #ebeef5;
}

.el-form-item {
  margin-bottom: 20px;
}

.full-width {
  width: 100%;
}

/* Optional: Add some hover effects for buttons */
.el-button:hover {
  background-color: #67c23a;
  border-color: #67c23a;
  color: #fff;
}
</style>